package com.eastfair.home.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.home.dto.ExhibitionSiteDrawingDTO;
import com.eastfair.home.dto.ExhibitionSiteDrawingPageQuery;
import com.eastfair.home.dto.ExhibitionSiteDrawingSaveDTO;
import com.eastfair.home.dto.ExhibitionSiteDrawingUpdateDTO;
import com.eastfair.home.entity.ExhibitionSiteDrawing;
import com.eastfair.home.service.ExhibitionSiteDrawingService;
import com.eastfair.home.vo.ExhibitionSiteDrawingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 展会展位图纸
 * </p>
 *
 * @author dqq
 * @date 2022-12-27
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/exhibitionSiteDrawing")
@Api(value = "ExhibitionSiteDrawing", tags = "展会展位图纸")
@PreAuth(replace = "home:exhibitionSiteDrawing:")
public class ExhibitionSiteDrawingController extends SuperController<ExhibitionSiteDrawingService, Long, ExhibitionSiteDrawing, ExhibitionSiteDrawingPageQuery, ExhibitionSiteDrawingSaveDTO, ExhibitionSiteDrawingUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private ExhibitionSiteDrawingService exhibitionSiteDrawingService;

    @Override
    public void handlerResult(IPage<ExhibitionSiteDrawing> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ExhibitionSiteDrawing> exhibitionSiteDrawingList = list
                .stream()
                .map((map) -> ExhibitionSiteDrawing.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(exhibitionSiteDrawingList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ExhibitionSiteDrawingPageQuery> params) {
        ExhibitionSiteDrawingPageQuery pageQuery = params.getModel();
    }

    /**
     * 分页查询展会展位图纸列表.
     *
     * @param pageParams the page params
     * @return the r
     */
    @ApiOperation("分页查询展会展位图纸列表")
    @PostMapping("/query/exhibitionSiteDrawing")
    public R<Page<ExhibitionSiteDrawingVO>> queryExhibitionSiteDrawing(@RequestBody PageParams<ExhibitionSiteDrawingDTO> pageParams) {
        log.info("queryExhibitionSiteDrawing - 分页查询展会展位图纸列表, pageParams={}", pageParams);
        return R.successDef(exhibitionSiteDrawingService.listExhibitionSiteDrawingVO(pageParams));
    }

    /**
     * 保存展会展位图纸.
     *
     * @param exhibitionSiteDrawingDTO the exhibition site drawing dto
     * @return the r
     */
    @ApiOperation("保存展会展位图纸")
    @PostMapping("/save")
    public R<Boolean> saveExhibitionSiteDrawing(@RequestBody ExhibitionSiteDrawingDTO exhibitionSiteDrawingDTO) {
        log.info("saveExhibitionSiteDrawing - 保存展会展位图纸, exhibitionSiteDrawingDTO={}", exhibitionSiteDrawingDTO);
        return R.successDef(exhibitionSiteDrawingService.saveExhibitionSiteDrawing(exhibitionSiteDrawingDTO));
    }
}
